//
//  SteppedSlider.swift
//  SwiftPhtotEdit
//
//  Created by aw031 on 15/10/2025.
//

import UIKit

public typealias SliderChangeValueBlock = (_ slider : UISlider) -> Void


class SteppedSlider: UISlider {
    var step: Float = 1.0
    var changeValueBlock : SliderChangeValueBlock?
    override init(frame: CGRect) {
        super.init(frame: frame)
        setup()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
        setup()
    }
    
    
    private func setup() {
        self.addTarget(self, action: #selector(handleValueChange), for: .valueChanged)
    }
    
    
    @objc private func handleValueChange() {
        let roundedValue = round(self.value / step) * step
        self.value = roundedValue
        self.changeValueBlock?(self)
    }
    
    // 获取整数值
    var intValue: Int {
        return Int(self.value)
    }
}
